package com.enki.adminplatform.exception;

import com.baomidou.mybatisplus.extension.api.R;
import com.enki.adminplatform.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yinyin
 * @create 2021/07/22 下午 6:04
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handler(Exception e){
        e.printStackTrace();
        return Result.error();
    }
    @ExceptionHandler(CaptchaException.class)
    @ResponseBody
    public Result handler(CaptchaException e){
        e.printStackTrace();
        return Result.error().message(e.getMessage());
    }
    @ExceptionHandler(EnkiException.class)
    @ResponseBody
    public Result handler(EnkiException e){
        e.printStackTrace();
        return Result.error().message(e.getMessage()).code(e.getCode());
    }
}
